package com.bdd.service.impl;

import com.bdd.common.AjaxResponseResult;
import com.bdd.common.IdentityStatus;
import com.bdd.dao.IdentityDao;
import com.bdd.dto.IdentityDto;
import com.bdd.entities.Identity;
import com.bdd.service.IdentityService;
import com.bdd.service.UserFeignService;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @Author Bdd
 * @Description
 * @Date 2020/3/31 21:13
 */
@Service
public class IdentityServiceImpl implements IdentityService {

    @Resource
    private IdentityDao identityDao;

    @Resource
    private UserFeignService userFeignService;

    @Override
    public AjaxResponseResult realNameAuth(IdentityDto identityDto) {
        Identity identity = new Identity();
        BeanUtils.copyProperties(identityDto,identity);
        identity.setIdentityStatus(IdentityStatus.AUTHENTICATED.getStatus());
        System.out.println(identity);
        int result = identityDao.realNameAuth(identity);
        if(result > 0){
            //调用A
            userFeignService.auth(identity.getId());
            return new AjaxResponseResult(200,"认证成功");
        }
        return new AjaxResponseResult(400,"认证失败");
    }

    @Override
    public AjaxResponseResult save(IdentityDto identityDto) {
        Identity identity = new Identity();
        BeanUtils.copyProperties(identityDto,identity);
        identity.setIdentityStatus(IdentityStatus.UNAUTHORIZED.getStatus());
        identityDao.save(identity);
        return new AjaxResponseResult(200,"同步调用成功");
    }
}
